package com.yw.swagger.service.serviceImpl;

import com.yw.swagger.mapper.AuthorMapper;
import com.yw.swagger.mapper.SpKaoQinMapper;
import com.yw.swagger.mapper.SysBpsGpmemlnkMapper;
import com.yw.swagger.model.SpKaoQin;
import com.yw.swagger.model.SysBpsGpmemlnk;
import com.yw.swagger.model.SysBpsUsers;
import com.yw.swagger.service.SpKaoQinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @Author: Abeiv
 * @Description:
 * @Date: 2019/10/26 10:43
 */
@Service
public class SpKaoQinServiceImpl implements SpKaoQinService {

    @Autowired
    private AuthorMapper authorMapper;
    @Autowired
    private SpKaoQinMapper spKaoQinMapper;
    @Autowired
    private SysBpsGpmemlnkMapper sysBpsGpmemlnkMapper;
    //添加考勤
    @Override
    public int insertAddKaoQin(SpKaoQin kaoQin, List<String> date, List<String> dro) {
        try {
//            String []name=kaoQin.getFullname().split(",");
//            String []day=date.split(",");
            System.err.println(dro);
            SpKaoQin sp=new SpKaoQin();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            int k=0;
//            for(int i=0;i<name.length;i++){
                for (int j=0;j<dro.size();j++){
                    sp.setBm(kaoQin.getBm());
//                  sp.setFullname(name[i]);
                    sp.setFullname(kaoQin.getFullname());
                    sp.setKqdate(simpleDateFormat.parse(date.get(j)));
                    sp.setQdqk(dro.get(j));
                    sp.setKsdate(simpleDateFormat.parse(date.get(0)));
                    sp.setJsdate(simpleDateFormat.parse(date.get(date.size()-1)));
                    k=k+spKaoQinMapper.insertAddKaoQin(sp);
                    System.err.println(1);
                }
//            }
            return k;
        }catch (Exception e){
            e.getMessage();
            System.err.println("e:"+e.getMessage());
        }

        return 0;
    }
    //修改考勤
    @Override
    public int updateKaoQin(SpKaoQin kaoQin, List<String> datel, List<String> drol){
        try {
            SpKaoQin sp=new SpKaoQin();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            int k=0;
//            for(int i=0;i<name.length;i++){
            for (int j=0;j< drol.size();j++){
                sp.setBm(kaoQin.getBm());
//              sp.setFullname(name[i]);
                sp.setFullname(kaoQin.getFullname());
                sp.setKqdate(simpleDateFormat.parse(datel.get(j)));
                sp.setQdqk(drol.get(j));
                sp.setKsdate(simpleDateFormat.parse(datel.get(0)));
                sp.setJsdate(simpleDateFormat.parse(datel.get(datel.size()-1)));
                k=k+spKaoQinMapper.updateKaoQin(sp);
            }
//            }
            return k;
        }catch (Exception e){
            e.getMessage();
            System.err.println("e:"+e.getMessage());
        }
        return 0;
    }

    //部门人员
    @Override
    public List<SysBpsGpmemlnk> selectDeptPerson(String send) {
        List<SysBpsGpmemlnk> l = sysBpsGpmemlnkMapper.selectDeptPerson(send);
        System.err.println(l);
        return l;
    }
    //查询部门所有的人的考勤
    @Override
    public List<SpKaoQin> selectKaoqin(List<String> person,String ksDate,String jsDate) {
        //查询部门所有的人的考勤
        List<SpKaoQin> kaoqin=spKaoQinMapper.selectKaoqin(person,ksDate,jsDate);
        return kaoqin;
    }
    //查询操作考勤者职位
    @Override
    public SysBpsUsers selectoaRoleName(String account) {
        return spKaoQinMapper.selectoaRoleName(account);
    }
    //查询有没有此人的考勤
    @Override
    public String selectKaoqinDetails(String fullname, String date) {
        return spKaoQinMapper.selectKaoqinDetails(fullname,date);
    }
    //查询当前登录账号是否有考勤权限
    @Override
    public List<String> selectMoedl(String roleID) {
        return spKaoQinMapper.selectMoedl(roleID);
    }

    @Override
    public List<String> selectMoedlLimits(List<String> list) {
        return spKaoQinMapper.selectMoedlLimits(list);
    }

    //查询个人本周考勤
    @Override
    public List<SpKaoQin> selectPersonKaoqin(String userName, String ksDate, String jsDate) {
        return spKaoQinMapper.selectPersonKaoqin(userName,ksDate,jsDate);
    }
}
